/* GUI CONVERTED from reop11b.p (converter v1.76) Tue Apr 23 11:43:53 2002 */
/* reop11b.p - LABOR REJECT TRANSACTION BY PART (REPETITIVE)            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.7.1.3 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.3      LAST MODIFIED: 02/24/93   BY: emb *G760*/
/* Oracle changes (share-locks)    09/12/94           BY: rwl *FR25*    */
/* REVISION: 7.5      LAST MODIFIED: 11/22/94   BY: taf *J038*/
/* REVISION: 8.5    LAST MODIFIED: 12/26/96 BY: *H0Q8* Julie Milligan   */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb              */
/* Old ECO marker removed, but no ECO header exists *F003*                    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *G382*                    */
/* Old ECO marker removed, but no ECO header exists *G689*                    */
/* $Revision: 1.7.1.3 $    BY: Robin McCarthy        DATE: 01/31/02  ECO: *P000*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reop11b_p_1 "Conv"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define shared variable wr_recno as recid.
define shared variable wo_recno as recid.
define shared variable eff_date as date.

define variable last_date like op_date.
define variable rsn_desc1 like rsn_desc.
define variable shift like op_shift.
define shared variable site like rps_site no-undo.
define shared variable prline like rps_line no-undo.
define variable ro_recid as recid.
define variable ptstatus like pt_status.

define shared variable part like op_part no-undo.
define shared variable op like ps_op no-undo.
define shared variable bom_code as character format "x(18)".
define shared variable routing as character format "x(18)".
define shared variable schedule_id like wo_lot.
define variable msg-type as integer.
define shared variable undo-all like mfc_logical no-undo.
define shared variable mod_issrc like mfc_logical.
define shared variable conv like um_conv label {&reop11b_p_1}.
define variable um like pt_um.
define variable tot_units like op_qty_comp.
define variable disp_units as character format "x(15)".
define variable temp_qty like pk_qty no-undo.
define variable trqty like sr_qty no-undo.

/*****************/
define shared variable comp like ps_comp.
define shared variable wo_recid as recid.
define shared variable ophist_recid as recid.

define variable i as integer.
define variable yn like mfc_logical.
define variable ref like glt_ref.
define variable wr_recid as recid.
define buffer ophist for op_hist.
define variable location as character.
define shared frame a.

/* DEFINE VARIABLES FOR BILL OF MATERIAL EXPLOSION */
{gpxpld01.i "shared"}
/*****************/

{reopf11a.i}

find wo_mstr no-lock where recid(wo_mstr) = wo_recno.
find wr_route no-lock where recid(wr_route) = wr_recno.
find op_hist where recid(op_hist) = ophist_recid.

comp = wr_part.
if wo_bom_code <> "" then comp = wo_bom_code.
eff_date = op_date.

operation = wr_op.
op_qty_rjct = op_qty_rjct * conv.
op_qty_comp = op_qty_comp * conv.

op_list = "".
if schedule_id > "" then do:

   {mfdel.i pk_det "where pk_user = mfguser"}

   for each wo_mstr no-lock where wo_lot = schedule_id,
         each wr_route no-lock where wr_lot = schedule_id
         and wr_op <= operation
         by wr_lot descending by wr_op descending:
/*GUI*/ if global-beam-me-up then undo, leave.

      if wr_milestone = yes and wr_op < operation then leave.
      op_list = op_list
      + fill(",",if op_list = "" then 0 else 1)
         + string(wr_op).

      if can-find (loc_mstr where loc_loc = wr_wkctr
         and loc_site = wo_site) then location = wr_wkctr.
      else location = "".

      {gprun.i ""reopex01.p""
         "(wr_lot,wr_op,wo_site,wo_qty_ord,location)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.

end.
else do:
   for each ro_det no-lock where
         ro_routing = (if routing > "" then routing else wr_part)
         and ro_op <= operation
         and (ro_start <= eff_date or ro_start = ?)
         and (ro_end >= eff_date or ro_end = ?)
         by ro_routing descending by ro_op descending:
      if ro_milestone = yes and ro_op < operation then leave.
      op_list = op_list
      + fill(",",if op_list = "" then 0 else 1)
         + string(ro_op).
   end.

   /* EXPLODE ASSEMBLY FOR THIS OPERATION TO ISSUE COMPONENTS */
   {gpxpldps.i &date=eff_date
      &site=site
      &comp=comp
      &op=operation
      &op_list=op_list
      }

end.

/* CREATE FROZEN BILL OF MATERIALS FOR THIS ASSEMBLY*/
find first icc_ctrl no-lock.

find wo_mstr no-lock where recid(wo_mstr) = wo_recno.
find wr_route no-lock where recid(wr_route) = wr_recno.

for each pk_det exclusive-lock where pk_user = mfguser
      break by pk_user
      by pk_part
      by pk_reference:

   /* BREAK BY IS USED TO CONSOLIDATE LIKE PART/REFERENCE  */
   /* NUMBER INTO ONE PK_DET RECORD.  PK_REFERENCE STORES  */
   /* THE OPERATION NUMBER.                                */

   if first-of(pk_reference) then temp_qty = 0.
   assign temp_qty = temp_qty + pk_qty.
   if not last-of(pk_reference) then delete pk_det.
   else do:
      pk_qty = temp_qty.

      /* GET THE DEFAULT LOCATION IF NO SCHEDULE EXISTS */
      if schedule_id = "" then do:
         if op_wo_op <> integer(pk_reference) then do:

            find first ro_det no-lock where
               ro_routing = (if routing > "" then routing else wr_part)
               and ro_op = integer(pk_reference)
               and (ro_start <= eff_date or ro_start = ?)
               and (ro_end >= eff_date or ro_end = ?) no-error.
            if available ro_det
               and can-find (loc_mstr where loc_loc = ro_wkctr
               and loc_site = site) then pk_loc = ro_wkctr.

         end.
         else do:
            if can-find(loc_mstr where loc_site = wo_site and
               loc_loc = op_wkctr) then pk_loc = op_wkctr.
         end.
      end. /* if schedule_id = "" */

      else if op_wo_op = integer(pk_reference) then do:
         if can-find(loc_mstr where loc_site = wo_site and
            loc_loc = op_wkctr) then pk_loc = op_wkctr.
      end. /* schedule_id <> "" */

      find first wod_det where wod_lot = wo_lot
         and wod_part = pk_part
         and (wod_op = integer(pk_reference))
         no-error.
      if not available wod_det then do:
         find in_mstr where in_part = pk_part and in_site = wo_site
         no-lock no-error.
         if available in_mstr then do:
            if in_gl_set = "" then find
               sct_det where sct_part = in_part
               and sct_sim = icc_gl_set
               and sct_site = in_gl_cost_site no-lock no-error.
            else find
               sct_det where sct_part = in_part
               and sct_sim = in_gl_set
               and sct_site = in_gl_cost_site no-lock no-error.
         end.
         else do:
            find si_mstr where si_site = wo_site no-lock no-error.
            if available si_mstr and si_gl_set = "" then
               find sct_det where sct_part = pk_part
               and sct_sim = icc_gl_set
               and sct_site = wo_site no-lock no-error.
            else
               find sct_det where sct_part = pk_part and sct_sim = si_gl_set
               and sct_site = si_site no-lock no-error.
         end.

         create wod_det.
         assign wod_lot = wo_lot
            wod_nbr = wo_nbr
            wod_part = pk_part
            wod_op = integer(pk_reference)
            wod_site = wo_site
            wod_bom_qty = pk_qty / bombatch
            wod_loc = ?
            wod_iss_date = ?.
         if available sct_det then wod_bom_amt = sct_cst_tot.

         find qad_wkfl where qad_key1 = "MFWORLA"
            and qad_key2 = wod_lot + wod_part + string(wod_op) no-error.
         if not available qad_wkfl then do:
            create qad_wkfl.
            assign qad_key1 = "MFWORLA"
               qad_key2 = wod_lot + wod_part + string(wod_op).
         end.
         qad_decfld[1] = pk_qty.
         qad_decfld[2] = bombatch.

      end.

      find first pkwkfl where pkrecid = recid(pk_det)
      no-lock no-error.
      if available pkwkfl and isspol = no then do:
         wod_qty_req = wod_qty_req
         + (pk_qty * (op_qty_comp + op_qty_rjct)) / bombatch.
         wod_qty_iss = wod_qty_req
         + (wod_qty_iss * (op_qty_comp + op_qty_rjct)) / bombatch.
         delete pk_det.
      end.
   end. /* last-of (pk_reference) */

end. /* for each pk_det */

if mod_issrc = no
   and (op_qty_comp <> 0 or op_qty_rjct <> 0) then
for each pk_det no-lock where pk_user = mfguser
      and pk_qty <> 0
      break by pk_user
      by pk_part
      by pk_loc:
/*GUI*/ if global-beam-me-up then undo, leave.


   if first-of(pk_part) then do:
      find pt_mstr no-lock where pt_part = pk_part no-error.
      if available pt_mstr and index("LS",pt_lot_ser) > 0 then do:
         mod_issrc = yes.
         {pxmsg.i &MSGNUM=1119 &ERRORLEVEL=1}
         leave.
      end.
   end. /*first-of(pk_part) */
   if first-of(pk_loc) then trqty = 0.
   trqty = trqty + pk_qty.

   define variable rejected like mfc_logical.
   {gprun.i ""icedit2.p"" "(input ""ISS-WO"",
        input wo_site,
        input pk_loc,
        input pk_part,
        input """",
        input """",
        input trqty / bombatch,
        input if available pt_mstr
        then pt_um else """",
        """",
        """",
        output rejected)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if rejected then do:
      mod_issrc = yes.
      leave.
   end.
end.
/*GUI*/ if global-beam-me-up then undo, leave.


if mod_issrc then do:
   hide frame a no-pause.
   {gprun.i ""reisrc01.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   view frame a.
end.
